from itsdangerous import TimedJSONWebSignatureSerializer


class MySerect(object):
    def __init__(self, secret_key):
        self.ser = TimedJSONWebSignatureSerializer(secret_key=secret_key)

    # 加密
    def dumps(self, data):
        result = self.ser.dumps(data)
        return result.decode()

    # 解密
    def loads(self, data):
        try:
            result =  self.ser.loads(data)
        except Exception as e:
            print(e)
            return None

        return result

if __name__ == '__main__':
    ser = MySerect('abdsdfs33')
    result = ser.dumps([1,2,3])
    print(result)
    result = ser.loads('2134343')
    print(result)